package demo.miner;

import java.awt.Image;
import java.util.HashMap;
import java.util.Map;

import jtech.core.Loader;


public abstract class ClassEntity {

	public enum ClassName {

		PEASANT, ARCHERY, FOOTMAN,
		
		GOLDMINE, BARRACKS
		
	}
	
	private static Map<ClassName, ClassEntity> classes = new HashMap<ClassName, ClassEntity>();

	public static void add(ClassEntity cEntity) {
		classes.put(cEntity.getName(), cEntity);
	}

	public static ClassEntity get(ClassName name) {
		return classes.get(name);
	}

	public static ClassEntity remove(ClassName name) {
		return classes.remove(name);
	}
	
	
	private ClassName name;
	private Class<? extends Entity<?>> entityClass;

	private String spriteImagePath;
	private Image  spriteImage;
	private int    spriteOffsetX;
	private int    spriteOffsetY;
	private int    spriteWidth;
	private int    spriteHeight;

	private int   baseHitPoints;
	private int   baseArmor;
	private int   baseDamage;
	private int   baseAttackRange;
	private float baseReloadTime;
	private float baseRadius;
	
	private boolean canAttack;
	
	private int     goldCost;
	
	public ClassEntity() {
		
	}

	public ClassEntity(Class<? extends Entity<?>> entityClass) {
		this.entityClass = entityClass;
	}
	
	public Class<?> getEntityClass() {
		return entityClass;
	}

	public void setEntityClass(Class<? extends Entity<?>> entityClass) {
		this.entityClass = entityClass;
	}

	public Image getSpriteImage() {
		return spriteImage;
	}

	public void setSpriteImage(Image spriteGraphic) {
		this.spriteImage = spriteGraphic;
		this.spriteImagePath = null;
	}
	
	public void setSpriteImagePath(String spriteImagePath) {
		this.spriteImagePath = spriteImagePath;
		this.spriteImage = Loader.getInstance().loadImage(spriteImagePath, spriteImagePath);
	}

	public String getSpriteImagePath() {
		return spriteImagePath;
	}

	public int getSpriteOffsetX() {
		return spriteOffsetX;
	}

	public void setSpriteOffsetX(int spriteOffsetX) {
		this.spriteOffsetX = spriteOffsetX;
	}

	public int getSpriteOffsetY() {
		return spriteOffsetY;
	}

	public void setSpriteOffsetY(int spriteOffsetY) {
		this.spriteOffsetY = spriteOffsetY;
	}

	public int getSpriteWidth() {
		return spriteWidth;
	}

	public void setSpriteWidth(int spriteWidth) {
		this.spriteWidth = spriteWidth;
	}

	public int getSpriteHeight() {
		return spriteHeight;
	}

	public void setSpriteHeight(int spriteHeight) {
		this.spriteHeight = spriteHeight;
	}

	public int getBaseHitPoints() {
		return baseHitPoints;
	}

	public void setBaseHitPoints(int baseHitPoints) {
		this.baseHitPoints = baseHitPoints;
	}

	public int getBaseArmor() {
		return baseArmor;
	}

	public void setBaseArmor(int baseArmor) {
		this.baseArmor = baseArmor;
	}

	public int getBaseDamage() {
		return baseDamage;
	}

	public void setBaseDamage(int baseDamage) {
		this.baseDamage = baseDamage;
	}

	public int getBaseAttackRange() {
		return baseAttackRange;
	}

	public void setBaseAttackRange(int baseAttackRange) {
		this.baseAttackRange = baseAttackRange;
	}

	public float getBaseReloadTime() {
		return baseReloadTime;
	}

	public void setBaseReloadTime(float baseReloadTime) {
		this.baseReloadTime = baseReloadTime;
	}

	public float getBaseRadius() {
		return baseRadius;
	}

	public void setBaseRadius(float baseRadius) {
		this.baseRadius = baseRadius;
	}

	public int getGoldCost() {
		return goldCost;
	}

	public void setGoldCost(int goldCost) {
		this.goldCost = goldCost;
	}

	public ClassName getName() {
		return name;
	}

	public void setName(ClassName name) {
		this.name = name;
	}
	
	public boolean isCanAttack() {
		return canAttack;
	}

	public void setCanAttack(boolean canAttack) {
		this.canAttack = canAttack;
	}

	public Entity<?> newInstance() {
		try {
			return (Entity<?>) getEntityClass().getConstructor(getClass()).newInstance(this);
		} catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
}